//轮播
let arr = ["jc_index_rotate1.jpg","jc_index_rotate2.jpg","jc_index_rotate3.jpg"];
let j = 0;
let divs = document.querySelectorAll(".rotate_bar>div");
setInterval(() =>{
    divs.forEach(obj =>{
        obj.className = "";
    });
    j++;
    j > 2&&(j = 0);
    let link = "../img/"+arr[j];
    $(".rotate img").attr("src",link);
    divs[j].className = "strip";
},3000)
//渲染
function random1(){
    $.getJSON("http://192.168.10.105/daojucheng-juchengpin/project/php/sever.php?key=?","hide=recommend",data =>{
        var arr1 = new Array();
            var arr2 = new Array();
            for(var i = 0; i<7; i++){
                arr1.push(i);
            }
        for(var k = 0; k<4;k++){
            var id = Math.ceil(Math.random()*6);              
            if(arr2.indexOf(arr1[id]) === -1){
                arr2.push(arr1[id]);                   
            }else{                 
                k= k - 1;
                continue;
            }            
        }
        arr2.forEach(obj =>{
            let img = data[obj-1].link;
            let li = $(`<li><img src=../img/${img} width='280' height='375'></li>`);
            $(".rec-list>ul").append(li);
        })
    },"JSON")
}
random1();
function random2(){
    $.getJSON("http://192.168.10.105/daojucheng-juchengpin/project/php/sever.php?key=?","hide=limitTime",data =>{
        var arr1 = new Array();
            var arr2 = new Array();
            for(var i = 0; i<45; i++){
                arr1.push(i);
            }
        for(var k = 0; k<4;k++){
            var id = Math.ceil(Math.random()*44);              
            if(arr2.indexOf(arr1[id]) === -1){
                arr2.push(arr1[id]);                   
            }else{                 
                k= k - 1;
                continue;
            }            
        }
        arr2.forEach(obj =>{
            let img = data[obj-1].link;
            let name = data[obj-1].name;
            let price = data[obj-1].newprice;
            let li = $(`<li><img src=../img/${img} width='280' height='268'><div class='good-info'><p class='good-name'>${name}</p><p class='good-pri'>￥${price}</p></div></li>`);
            $(".good-list:eq(0)>ul").append(li);
        })
    },"JSON")
}
random2();
function random3(){
    $.getJSON("http://192.168.10.105/daojucheng-juchengpin/project/php/sever.php?key=?","hide=toys",data =>{
        var arr1 = new Array();
            var arr2 = new Array();
            for(var i = 0; i<7; i++){
                arr1.push(i);
            }
        for(var k = 0; k<4;k++){
            var id = Math.ceil(Math.random()*6);              
            if(arr2.indexOf(arr1[id]) === -1){
                arr2.push(arr1[id]);                   
            }else{                 
                k= k - 1;
                continue;
            }            
        }
        arr2.forEach(obj =>{
            let img = data[obj-1].link;
            let name = data[obj-1].name;
            let price = data[obj-1].price;
            let li = $(`<li><img src=../img/${img} width='280' height='268'><div class='good-info'><p class='good-name'>${name}</p><p class='good-pri'>￥${price}</p></div></li>`);
            $(".good-list:eq(1)>ul").append(li);
        })
        // console.log(data);
    },"JSON")
}
random3();
$(".link-more:first").click(() =>{
    $(".rec-list>ul").html("");
    random1();
});
$(".link-more:eq(1)").click(() =>{
    $(".good-list:eq(0)>ul").html("");
    random2();
});
$(".link-more:eq(2)").click(() =>{
    $(".good-list:eq(1)>ul").html("");
    random3();
});